package com.hdjk.view.callback;

import com.hdjk.view.entity.UserEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class RecommendListCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONArray array = (JSONArray) msg.getData();
        if (array!=null) {
            List<UserEntity> list = new ArrayList<>();
            for (int j = 0; j < array.length(); j++) {
                JSONObject object = array.getJSONObject(j);
                UserEntity entity = new UserEntity();
                if (!object.isNull("Name")) {
                    entity.setName(object.getString("Name"));
                }
                if (!object.isNull("RefereeId")) {
                    entity.setRefereeId(object.getString("RefereeId"));
                }
                if (!object.isNull("CreateTime")) {
                    entity.setCreateTime(object.getString("CreateTime"));
                }
                list.add(entity);
            }
            msg.setData(list);
        }
        return msg;
    }
}
